package cn.edu.scut.hsrc.test;

import java.io.File;
import java.io.OutputStreamWriter;
import java.util.Random;

import cn.edu.scut.hsrc.bean.Doc;
import cn.edu.scut.hsrc.cluster.HSRC;
import cn.edu.scut.hsrc.input.FileInputAdapter;
import cn.edu.scut.hsrc.input.InputAdapter;
import cn.edu.scut.hsrc.output.ClusterResult;
import cn.edu.scut.hsrc.util.OutputUtil;

/**
 * 测试异步调用HSRC
 * @author feiyu
 *
 */
public class BaiduClusterTest1 {
	private static void testCluster()
	{
		final String [] sites = {"北大科研论文","华南教育新闻","北京大学","清华大学","华南木棉"};
		long curr = System.currentTimeMillis();
		long TWOYEAR = 2l;
		TWOYEAR = TWOYEAR*365*24*3600*1000;
		int HOUR = 2*365*24;
		//读取文档
		String query = "北京大学";
		File file = new File("F:/BaiduData/results/"+query);
		InputAdapter input = new FileInputAdapter(file);
		Doc [] docs = input.initData(0, 100).toArray(new Doc[0]);
		Random random = new Random();
		for (Doc doc : docs) {
			doc.setSite(sites[random.nextInt(sites.length)]);
			doc.setTime(curr-((long)random.nextInt(HOUR))*3600*1000);
		}

		HSRC hsrc = new HSRC(true, true, true);
		//HSRC hsrc = new HSRC(true, false, false);
		//HSRC hsrc = new HSRC(false, true, false);
		//HSRC hsrc = new HSRC(false, false, true);
		hsrc.doCluster(query, docs);
		ClusterResult [] semanticResults = hsrc.getSemanticClusterResults();
		ClusterResult [] siteResults = hsrc.getSiteClusterResults();
		ClusterResult [] timeResults = hsrc.getTimeClusterResults();
		
		//输出到屏幕
		//OutputUtil.print(query, Arrays.asList(clusterResults), new OutputStreamWriter(System.out));
		System.out.println("\n语义聚类标签：");
		OutputUtil.printLabel(query, semanticResults, new OutputStreamWriter(System.out));	
		System.out.println("\n时间聚类标签：");
		OutputUtil.printLabel(query, timeResults, new OutputStreamWriter(System.out));
		System.out.println("\n站点聚类标签：");
		OutputUtil.printLabel(query, siteResults, new OutputStreamWriter(System.out));
	}
	
	public static void main(String[] args) {
		testCluster();
	}
}

